define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feedback/index' + location.search,
                    del_url: 'feedback/del',
                    multi_url: 'feedback/multi',
                    table: 'yexam_subject',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                escape: false,
                pk: 'id',
                sortName: 'id',
                sortOrder:'asc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'weigh', title: "排序",operate: false, editable: true},
                        {field: 'id', title: __('Id')},
                        {field: 'short_name', title: __('简称'),align: 'left',operate:'LIKE'},
                        //{field: 'subject_name', title: __('科目名称'),align: 'left', editable: true,operate:'LIKE'},
                        {field: 'en_name', title: __('英文名'),align: 'left', editable: true, operate: false},
                        {field: 'category_id', title: __('分类'),align: 'left',width:'60px',operate:'LIKE'},
                        {field: 'package_ids', title: __('班次'),width: '300px',align: 'left', operate: false},
                        //{field: 'content_json', title: __('科目信息'),align: 'left'},
                        {field: 'status', title: "是否显示",operate: false, formatter: Table.api.formatter.toggle},
                        //{field: 'createtime', title: __('添加时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons : [
                                {
                                    name: 'combo',
                                    title: __('套餐管理'),
                                    text: __('套餐管理'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-circle-o fa-fw',
                                    extend:'data-area=\'["60%","92%"]\'',
                                    url: 'yexam/subject_combo/index?subject_id={id}', // 无权限时不允显示
                                    //url: 'yexam/subject_combo/combo?subject_id={id}', // 无权限时不允显示
                                },
                            ]
                        }
                    ]
                ]
            });
            $(document).on('click', '.btn-mutil_price', function () {
                var ids = Table.api.selectedids(table);

                var url = "subject/mutil_price?ids="+ids;
                Fast.api.open(url, __('批量改价'), {
                    callback:function () {
                        table.bootstrapTable('refresh');
                    }
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        mutil_price: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter:{
                is_pay: function (value, row, index) {
                    return value?'是':'否';
                },
            },
            bindevent: function () {
                $("#c-package_ids").data("params", function (obj) {
                    return {custom: {category_id: $("#c-category_id").val()}};
                });
                Form.api.bindevent($("form[role=form]"));
            }
        },
    };
    return Controller;
});
